package itsm.isperp.module.controller.sparepart;

import itsm.isperp.framework.web.controller.BaseController;
import itsm.isperp.framework.web.response.ResultMessage;
import itsm.isperp.module.entity.sparepart.SptSparepartChangeDetail;
import itsm.isperp.module.entity.sparepart.SptSparepartInDetail;
import itsm.isperp.module.service.sparepart.SptSparepartInDetailService;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 备件管理控制器
 * 
 * @author lizx
 * @date 2013-9-12
 */
@Controller
@RequestMapping("sparepart/sparepartInDetail")
public class SptSparepartInDetailController extends
		BaseController<SptSparepartInDetail> {

	@Autowired
	protected SptSparepartInDetailService sptSparepartInDetailService;

	@Override
	public SptSparepartInDetailService getService() {
		return sptSparepartInDetailService;
	}

	@Override
	public String getPageTitle() {
		return "备件采购管理";
	}

	@RequestMapping("saveDetails")
	@ResponseBody
	public ResultMessage saveDetails(String relationId, String sparepartIds) {

		String[] sparepartIdArr = sparepartIds.split(",");
		sptSparepartInDetailService.batchSave(relationId, sparepartIdArr);
		return ResultMessage.success();
	}

	@RequestMapping("listBySparepartInId")
	@ResponseBody
	public List<Map<String, Object>> listBySparepartInId(String sparepartInId) {

		return this.sptSparepartInDetailService
				.findAllDetailBySparepartInId(sparepartInId);
	}
	
	@RequestMapping("addDetailEdit")
	public ModelAndView addDetailEdit(String id,String typeKey, HttpServletRequest req)
			throws Exception {
		ModelAndView mv = new ModelAndView("sparepart/sparepartIn/addDetailEdit");
		SptSparepartChangeDetail model=new SptSparepartChangeDetail();
		model.setSptSparepartId(id);
		model.setTypeKey(typeKey);
		mv.addObject("model", model);
		return mv;

	}
	

}
